<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="inputz" @keyup.enter="fn" />
    <table class="my-table">
      <thead>
        <tr>
          <th>就诊日期</th>
          <th>医生姓名</th>
          <th>诊断结果</th>
          <th>处方信息</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <MyBiao
          v-for="item in list"
          :key="item.id"
          :date="item.date"
          :uname="item.uname"
          :result="item.result"
          :information="item.information"
          :id="item.id"
        ></MyBiao>
      </tbody>
    </table>
  </div>
</template>

<script>
import MyBiao from './components/MyBiao.vue'
export default {
  components: {
    MyBiao,
  },
  data() {
    return {
      list: [
        {
          id: '1',
          date: new Date('2022-01-01'),
          uname: '张三',
          result: '感冒',
          information: '感冒药',
        },
        {
          id: 2,
          date: new Date(),
          uname: '李四',
          result: '头疼',
          information: '止疼药',
        },
        {
          id: 3,
          date: new Date(),
          uname: '王五',
          result: '腰疼',
          information: '止疼贴',
        },
      ],
      inputz: '',
      aa: '',
    }
  },
  //   没写出来想到了监听存本地作为判断条件，没实现代码删了
  //   这个思路也没实现
  //   预习了怕明天跟不上课
  methods: {
    fn() {
      this.aa = JSON.parse(JSON.stringify(this.list))
      this.list.forEach((item) => {
        if (this.inputz === item.uname) {
          console.log(1)
          const bb = this.list.filter((item) => item.uname === this.inputz)
          this.list = bb
          console.log(this.list)
        } else {
          this.list = this.aa
        }
      })
    },
  },
}
</script>

<style scoped>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
